<template>
</template>
<script lang="ts">
import * as THREE from 'three'
import { EffectComposer, OrbitControls, RenderPass, UnrealBloomPass } from 'three/examples/jsm/Addons.js';
import Stats from 'three/examples/jsm/libs/stats.module.js';

const scene = new THREE.Scene();


const width = 800;
const height = 800;
const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 100);
camera.position.set(0, 0, 5);
camera.lookAt(0, 0, 0);

const axesHelper = new THREE.AxesHelper(150);
scene.add(axesHelper);


const renderer = new THREE.WebGLRenderer({
    antialias: true,  // 开启抗锯齿
    powerPreference: "high-performance" // 可选：提升性能
});
renderer.setSize(width, height);
renderer.render(scene, camera);
document.body.appendChild(renderer.domElement);



const stats = new Stats;
stats.showPanel(0);
document.body.appendChild(stats.dom);
const controls = new OrbitControls(camera, renderer.domElement);
controls.addEventListener('change', () => {
    stats.update();
    renderer.render(scene, camera);
})


// === 创建路径 ===
const path = new THREE.CatmullRomCurve3([
  new THREE.Vector3(-10, 0, 0),
  new THREE.Vector3(-5, 5, 5),
  new THREE.Vector3(0, 0, 0),
  new THREE.Vector3(5, -5, 5),
  new THREE.Vector3(10, 0, 0)
]);

// === 创建管道 ===
const tubeGeometry = new THREE.TubeGeometry(path, 100, 2, 16, false);
const tubeMaterial = new THREE.MeshStandardMaterial({
  color: 0xff8800,
  side: THREE.DoubleSide,
  metalness: 0.1,
  roughness: 0.3
});
const tube = new THREE.Mesh(tubeGeometry, tubeMaterial);
scene.add(tube);

// === 添加光照 ===
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 1);
pointLight.position.set(10, 10, 10);
scene.add(pointLight);
    renderer.render(scene, camera);


// === 摄像机飞行动画 ===
// let t = 0;
// function animate() {
//   requestAnimationFrame(animate);

//   // 每帧更新曲线位置
//   t += 0.002;
//   if (t > 1) t = 0;

//   // 当前点位置
//   const position = path.getPoint(t);
//   camera.position.copy(position);

//   // 获取当前位置的切线（方向）
//   const tangent = path.getTangent(t).normalize();

//   // 让摄像机朝向下一个方向（模拟视角“自动转向”）
//   const lookAtPosition = position.clone().add(tangent);
//   camera.lookAt(lookAtPosition);

//   renderer.render(scene, camera);
// }
// animate();

</script>